<?php 
class Front_Payment_Generic extends System_Db_Generic  {
	public function getpaymentlist($params){
		$db = Zend_Registry :: get("db");
		$cmd_exec = "exec dbo.sp_Preauth_Get_translist NULL,'".$params['preauth_datefrom']."','".$params['preauth_dateto']."','".$params['userid']."','".$params['menu_num']."'";
		$statement = $db->prepare($cmd_exec);
		$statement->execute();
		$results = $statement->fetchAll();
		foreach ($results as $key=>$value){
			$results[$key]['preauth_datetime'] = getDateFormat2($results[$key]['preauth_datetime']);	
		}
		return $results;
	}
	public function getPaymentId(){
		$db = Zend_Registry :: get("db");
		$statement = $db->prepare('select dbo.FN_Payment_GenID () as payment_id');
		$statement->execute();
		$results = $statement->fetchAll();
		return $results['0']['payment_id'];
	}
	public function getPreAuthById($preauth_id,$user_id){
		$db = Zend_Registry :: get("db");
		$cmd_exec = "exec dbo.sp_Preauth_Get_translist '".$preauth_id."',NULL,NULL,'".$user_id."',NULL";
		$statement = $db->prepare($cmd_exec);
		$statement->execute();
		$results = $statement->fetchAll();
		foreach ($results as $key=>$value){
			$results[$key]['preauth_datetime'] = getDateFormat2($results[$key]['preauth_datetime']);
		}
		return $results;
	}
	public function getPolicyById($policy_id){
		if(!$policy_id) return;
		$db = Zend_Registry :: get("db");
		$cmd_exec = "exec dbo.sp_queryByPolicyId '$policy_id'";
		//echo $cmd_exec; exit();
		$statement = $db->prepare($cmd_exec);
		$statement->execute();
		$results = $statement->fetchAll();
		foreach ($results as $key=>$value){
			$results[$key]['effective'] = getDateFormat2($results[$key]['effective']);
			$results[$key]['expiry'] = getDateFormat2($results[$key]['expiry']);
			$results[$key]['me_cover'] = number_format($results[$key]['me_cover'],2,'.',',');
			$results[$key]['mc_cover'] = number_format($results[$key]['mc_cover'],2,'.',',');
		}
		return $results['0'];
	}
	
	public function getPlan2catByPlanId($plan_id){
		if(!$plan_id) return;
		$db = Zend_Registry :: get("db");
		$cmd_exec = "exec dbo.sp_getPlan2catByPlanid '$plan_id'";
		$statement = $db->prepare($cmd_exec);
		$statement->execute();
		$results = $statement->fetchAll();
		return $results['0'];
	}
	
	public function insertPayment($params){
		$db = Zend_Registry :: get("db");
		$cmd_exec = "exec dbo.sp_Payment_Trans_Save '".$params['payment_id']."','".$params['userid']."','".$params['preauth_id']."','".$params['policy_no']."','".$params['payment_datetime']."',
				'".$params['payment_status']."','".$params['customer_type']."','".$params['policy_id']."','".$params['payment_type']."','".$params['acc_date']."',
				'".$params['admis_date']."','".$params['deductible']."','".$params['charge']."','".$params['discount']."','".$params['co_payment']."',
				'".$params['pre_approved']."','".$params['non_covered']."','".$params['indiation_admit']."'";
		$statement = $db->prepare($cmd_exec);
		$results = $statement->execute();
		return $results;
	}
	
	public function getClaimCover(){
		$db = Zend_Registry :: get("db");
		$cmd_exec = "exec dbo.sp_Claim_Get_Cover_Type NULL";
		//echo $cmd_exec; exit();
		$statement = $db->prepare($cmd_exec);
		$statement->execute();
		$results = $statement->fetchAll();
		return $results;
	}
	public function getAccList($policy_id){
		$db = Zend_Registry :: get("db");
		$cmd_exec = "exec dbo.sp_Claim_Get_Acc_List '$policy_id'";
		$statement = $db->prepare($cmd_exec);
		$statement->execute();
		$results = $statement->fetchAll();
		return $results;
	}
	public function getClaimPreApp($params){
		$db = Zend_Registry :: get("db");
		$cmd_exec = "exec dbo.sp_Claim_PreApv_Cal '".$params['preauth_id']."','".$params['menu_seq']."','".$params['cover_type']."','".$params['acc_date']."','".$params['charge']."','".$params['discount']."'";
		$statement = $db->prepare($cmd_exec);
		$statement->execute();
		$_arr = $statement->fetchAll();
		$result = "[";
    	if($_arr){
    		$deduct = str_replace("\"","",$_arr['0']['deduct']);
    		$copay = str_replace("\"","",$_arr['0']['copay']);
    		$preapv = str_replace("\"","",$_arr['0']['preapv']);
    		$noncover = str_replace("\"","",$_arr['0']['noncover']);
    		$result .= "{\"deduct\":\"$deduct\"," .
    				   " \"copay\":\"$copay\"," .
    				   " \"preapv\":\"$preapv\"," .
    				   " \"noncover\":\"$noncover\"" .
    				   " }";
    	}
    	$result .= "]";
    	return $result;
	}
}
?>